package cn.micro.keep.accounts.service.impl;

import cn.micro.keep.accounts.common.utils.SecurityUtil;
import cn.micro.keep.accounts.entity.AccountDimCategory;
import cn.micro.keep.accounts.entity.dto.AccountDimCategoryDTO;
import cn.micro.keep.accounts.entity.dto.AccountDimCategorySearch;
import cn.micro.keep.accounts.entity.vo.AccountDimCategoryVO;
import cn.micro.keep.accounts.mapper.AccountDimCategoryMapper;
import cn.micro.keep.accounts.mapstruct.AccountDimCategoryMapstruct;
import cn.micro.keep.accounts.service.AccountDimCategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 账单分类信息表 服务实现类
 * </p>
 *
 * @author 柘阳科技
 * @since 2023-11-08
 */
@Service
public class AccountDimCategoryServiceImpl extends ServiceImpl<AccountDimCategoryMapper, AccountDimCategory> implements AccountDimCategoryService {

    @Override
    public boolean create(AccountDimCategoryDTO dto) {
        AccountDimCategory category = new AccountDimCategory();
        AccountDimCategoryMapstruct.INSTANCE.dtoToEntity(dto,category);
        category.setUserId(SecurityUtil.getUserId());
        return this.save(category);
    }

    @Override
    public boolean edit(AccountDimCategoryDTO dto) {
        AccountDimCategory category = new AccountDimCategory();
        AccountDimCategoryMapstruct.INSTANCE.dtoToEntity(dto,category);
        return this.updateById(category);
    }

    @Override
    public List<AccountDimCategoryVO> listByPage(AccountDimCategorySearch search) {
        PageHelper.startPage(search.getPageNum(),search.getPageSize());
        return this.baseMapper.queryByCondition(search);
    }
}
